unit ec_plugincommand;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ButtonPanel,
  ec_base, fpjson, LCLTranslator;

type

  { TECPluginCommandFrame }

  TECPluginCommandFrame = class(TECBaseFrame)
    CommandEdit: TEdit;
  private

  public
    procedure InitExisting; override;
    procedure MakeResultingCommand; override;
  end;

var
  ECPluginCommandFrame: TECPluginCommandFrame;

implementation

{$R *.lfm}

uses
  constants;

{ TECPluginCommandFrame }

procedure TECPluginCommandFrame.InitExisting;
var
  Params: TJSONArray;
begin
  inherited InitExisting;
  Params := GetFirstParams;

  if Params = nil then
     Exit;

  if (Params.Count >= 1) and (Params[0].JSONType = jtString) then
     CommandEdit.Text := Params.Strings[0];
end;

procedure TECPluginCommandFrame.MakeResultingCommand;
begin
  ResultingCommand := TJSONArray.Create([
    TJSONObject.Create([
      'code', PLUGIN_COMMAND_EC_CODE,
      'indent', Indent,
      'parameters', TJSONArray.Create([CommandEdit.Text])
    ])
  ]);
end;

end.

